package com.sfeir.poc.portal.gui.client.widgets;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;


public class CalcWidget extends AbstractWidget {

	public CalcWidget() {
		final TextBox firstVal = new TextBox();
		final TextBox secondVal = new TextBox();
		final Label result = new Label();
		Button addButton = new Button("+"); 
		Button delButton = new Button("-"); 
		Button multButton = new Button("*"); 
		Button divButton = new Button("/");
		Button equalButton = new Button("=");

		Grid grid = new Grid();
		grid.resize(4, 2);
		grid.setWidget(0, 0, firstVal);
		grid.setWidget(1, 0, secondVal);
		grid.setWidget(2, 0, equalButton);
		grid.setWidget(3, 0, result);
		grid.setWidget(0, 1, addButton);
		grid.setWidget(1, 1, delButton);
		grid.setWidget(2, 1, multButton);
		grid.setWidget(3, 1, divButton);

		addButton.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				Integer v1 = new Integer(firstVal.getText());				
				Integer v2 = new Integer(secondVal.getText());
				result.setText(v1+v2+"");
			}});

		delButton.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				Integer v1 = new Integer(firstVal.getText());				
				Integer v2 = new Integer(secondVal.getText());
				result.setText(v1-v2+"");
			}});

		multButton.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				Integer v1 = new Integer(firstVal.getText());				
				Integer v2 = new Integer(secondVal.getText());
				result.setText(v1*v2+"");
			}});

		divButton.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				Integer v1 = new Integer(firstVal.getText());				
				Integer v2 = new Integer(secondVal.getText());
				result.setText(v1/v2+"");
			}});
		widgetContainer.add(grid);
	}
}